#include"st7789.h"

TFT_eSPI lcd = TFT_eSPI();

void st7789_init(void) {
    lcd.init();
    // lcd.setBitmapColor(0xffff,0x0000);
    lcd.fillScreen(TFT_RED);
    delays(1);
    lcd.fillScreen(0x07e0);
    delays(1);
    lcd.fillScreen(0x001f);
    delays(1);

    // lcd.setTextColor(0xffff);
}

void st7789_test(void) {
    int8_t r;
    int8_t g;
    int8_t b;
    int32_t rgb;
    int8_t x_cnt;
    char buf[20]="0x0000";

    r=g=b=0x00;
    rgb=0;
    x_cnt=0;
    while(x_cnt<240) {
        if(r<0x1f) {
            ++r;
        } else if(g<0x3f) {
            ++g;
        } else if(b<0x1f) {
            ++b;
        } else {
            break;
        }

        snprintf(buf,5,"0x%02x",r);
        lcd.drawString(buf,4,4);
        snprintf(buf,5,"0x%02x",g);
        lcd.drawString(buf,4,14);
        snprintf(buf,5,"0x%02x",b);
        lcd.drawString(buf,4,24);
        rgb=(r<<11)|(g<<5)|(b<<0);
        // rgb=lcd.color24to16(rgb);
        snprintf(buf,7,"0x%04x",rgb);
        lcd.drawString(buf,4,34);
        lcd.drawFastVLine(x_cnt,44,180,rgb);
        ++x_cnt;
        delayms(4);
    }
    delays(2);
}